/**
 * @description User Controller
 */

 const {
  getWasteInfoFun,
  getReceiveInfoFun,
  getStageInfoFun,
  addData,
  updateData,
  deleteData,
  addWasteInfoFun,
  addStageInfoFun,
  updateStageInfoFun,
  addTransInfoFun,
  addHandleFun,
  getPackageTimelineFun,
  getWeightAbmormalFun,
  updateWasteInfoFun
} = require('../service/process')
const { SuccessModel, ErrorModel } = require('../model/ResModel')
const {
  queryFailInfo,
} = require('../model/ErrorInfo')


/**
 * 查询所有信息
 */
async function getWasteInfo(params) {
  try {
    const result = await getWasteInfoFun(params)
    return new SuccessModel(result)
  } catch (ex) {
    return new ErrorModel(queryFailInfo)
  }
}
async function getStageInfo(params) {
  try {
    const result = await getStageInfoFun(params)
    return new SuccessModel(result)
  } catch (ex) {
    return new ErrorModel(queryFailInfo)
  }
}

async function getReceiveInfo(params) {
  try {
    const result = await getReceiveInfoFun(params)
    return new SuccessModel(result)
  } catch (ex) {
    return new ErrorModel(queryFailInfo)
  }
}
/**
 * 新增信息
 */
async function addBackup(params) {
  try {
    await addData(params)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}
async function addStageInfo(params) {
  try {
    await addStageInfoFun(params)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}
async function addWasteInfo(params) {
  try {
    await addWasteInfoFun(params)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}
/**
 * 修改信息
 */
async function updateBackup(params, id) {
  try {
    await updateData(params, id)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}
async function updateStageInfo(params, id) {
  try {
    await updateStageInfoFun(params, id)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}

async function updateWasteInfo(params, id) {
  try {
    await updateWasteInfoFun(params, id)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}
/**
 * 删除
 */
 async function deleteBackup(id) {
  try {
    await deleteData(id)
    return new SuccessModel({
      msg: '删除成功'
    })
  } catch (ex) {
    return new ErrorModel({})
  }
}
async function addTransInfo(params) {
  try {
    await addTransInfoFun(params)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}

async function addHandle(params) {
  try {
    let rs = await addHandleFun(params)
    return new SuccessModel(rs)
  } catch (ex) {
    return new ErrorModel({})
  }
}
async function getPackageTimeline(params) {
  try {
    let rs = await getPackageTimelineFun(params)
    return new SuccessModel(rs)
  } catch (ex) {
    return new ErrorModel({})
  }
}
async function getWeightAbmormal(params) {
  try {
    let rs = await getWeightAbmormalFun(params)
    return new SuccessModel(rs)
  } catch (ex) {
    return new ErrorModel({})
  }
}

module.exports = {
  getWasteInfo,
  getStageInfo,
  addBackup,
  updateBackup,
  deleteBackup,
  getReceiveInfo,
  addStageInfo,
  addWasteInfo,
  updateStageInfo,
  addTransInfo,
  addHandle,
  getPackageTimeline,
  getWeightAbmormal,
  updateWasteInfo
}
